package chd.edu.spzx.manager.controller;

import chd.edu.spzx.manager.service.SysRoleMenuService;
import chd.edu.spzx.model.dto.system.AssignMenuDto;
import chd.edu.spzx.model.dto.system.AssignRoleDto;
import chd.edu.spzx.model.vo.common.Result;
import chd.edu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Zhang Chaoliang
 * create 2023
 * 为角色分配菜单控制类
 */
@RestController
@RequestMapping(value = "/admin/system/sysRoleMenu")
public class SysRoleMenuController {

    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    /**
     * 查询所有的菜单并且查询角色分配过的菜单
     * @param roleId
     * @return
     */
    @GetMapping(value = "/findSysRoleMenuByRoleId/{roleId}")
    public Result findSysRoleMenuByRoleId(@PathVariable(value = "roleId") Long roleId) {
        Map<String,Object> map = sysRoleMenuService.findSysRoleMenuByRoleId(roleId);
        return Result.build(map, ResultCodeEnum.SUCCESS);
    }

    /**
     * 保存角色分配菜单数据
     * @return
     */
    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssignMenuDto assignMenuDto) {
        sysRoleMenuService.doAssign(assignMenuDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }


}
